package com.pzl.mall;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.pzl.basic.beans.User;
import com.pzl.common.utils.QRCodeUtil;

@Route(path = "/mall/MallActivity")
public class MallActivity extends AppCompatActivity {
    ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mall);
        if (BuildConfig.isAppTest) Toast.makeText(this, "组件化APP测试模式", Toast.LENGTH_SHORT).show();
        else Toast.makeText(this, "组件化集成模式", Toast.LENGTH_SHORT).show();

        iv = findViewById(R.id.iv);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final Bundle b = new Bundle();
                b.putInt("a", 5);
                b.putInt("b", 2);
                b.putInt("c", 2);
                b.putInt("d", 3);

                Toast.makeText(MallActivity.this, "Go to Pay component ", Toast.LENGTH_SHORT).show();
                v.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ARouter.getInstance().build("/pay/PayActivity").
                                with(b).
                                navigation();
                    }
                }, 2000);
            }
        });

        if (getIntent().hasExtra("myUser")) {
            User myUser = (User) getIntent().getSerializableExtra("myUser");
            Toast.makeText(MallActivity.this, myUser.toString(), Toast.LENGTH_SHORT).show();
        }


    }

    public void click(View view) {
        int vID = view.getId();
        if (vID == R.id.btn_m1) {
        }
        if (vID == R.id.btn_m2) {
        }
        if (vID == R.id.btn_m3) {
        }
        Bitmap b = QRCodeUtil.generateQRCode(Long.toString(System.currentTimeMillis()), 300, 300);
        iv.setImageBitmap(b);
    }


}
